package com.ayoka.parenting.ui.mine;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.ViewGroup;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.GrownPathBean;
import com.ayoka.parenting.bean.PagerBean;
import com.ayoka.parenting.bean.UserInfoDetailBean;
import com.ayoka.parenting.bean.UserManager;
import com.ayoka.parenting.interf.SimpleRequestCallback;
import com.ayoka.parenting.mvp.BasePresenterImpl;
import com.ayoka.parenting.widget.NotificationDialog;
import com.jincp.common.dialog.DialogDismissListener;
import com.jincp.common.dialog.DialogResultListener;
import com.jincp.common.utils.UIUtils;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: MinePresenter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class MinePresenter extends BasePresenterImpl<MineContract.View> implements MineContract.Presenter{

    private MineModel model;

     public MinePresenter() {
        model = new MineModel();
     }

    @Override
    public void getUserInformation() {
        model.getUserInformation(this, new SimpleRequestCallback<UserInfoDetailBean>() {
            @Override
            public void onSuccess(UserInfoDetailBean data) {
                if (!isAttached()) return;
                UserManager.getInstance().detailBean = data;
                UserManager.save();
                mView.get().onGetUserInformationCallback(true);
            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                if (!isAttached()) return;
                mView.get().onGetUserInformationCallback(false);
            }
        });
    }

    @Override
    public void getGrownPathListData(boolean isShowWaitDialog, int pageNo, int pageSize) {
        if (isShowWaitDialog) {
            mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        }
        model.getGrownPathListData(this, pageNo, pageSize, new SimpleRequestCallback<PagerBean<GrownPathBean>>() {
            @Override
            public void onSuccess(PagerBean<GrownPathBean> data) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().configGrownPathListData(data);
            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errMsg);
            }
        });
    }

    @Override
    public void showNotificationDialog(FragmentManager fragmentManager) {
        String message = "甲方：上海嘎巴健康科技有限公司\n" +
                "乙方：哈巴教练\n" +
                "\t在甲乙双方合作过程中，甲乙双方就乙方承诺与甲方业务保密及不竞争达成本协议。\n" +
                "1.保密及不竞争承诺\n" +
                "\t鉴于乙方将作为甲方的合作伙伴，为甲方的用户提供产品使用的服务与反馈，且该合作将作为甲方商业产品/服务未来的重要形式，并成为甲方的商业秘密，以方在此承诺：\n" +
                "\t①.甲方与乙方的合作中服务形式与内容的所有权（包括但不限于知识产权）归属于甲方；\n" +
                "\t②.乙方有义务对合作过程中获得的甲方所有商业信息保密；\n" +
                "\t③.乙方承诺不使用合作过程中产生的内容用于商业行为，以及与甲方形成竞争的产品/服务中；\n" +
                "\t④.乙方承诺不会以任何其他形式使用合作过程中产生的内容，用于支持第三方产生与甲方业务构成竞争的产品与服务。\n" +
                "2、生效及期限\n" +
                "\t本协议自甲乙双方签字之日起生效，有效期为三年。\n" +
                "3、违约责任\n" +
                "\t任何一方未履行本协议项下的条款均被视为违约，作出违约行为的一方应承担因自己的违约行为而给守约方造成的损失。\n" +
                "同意以上“保密及不竞争协议”内容后，将下载“哈巴教练手册”。";
        final NotificationDialog dialog = new NotificationDialog.Builder()
                .setGravity(Gravity.CENTER)
                .setSize(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .setTitle("提示")
                .setMessage(message)
                .setNegativeText("放弃")
                .setPositiveText("同意")
                .build();
        dialog.setDialogResultListener(new DialogResultListener() {
            @Override
            public void result(DialogFragment dialogFragment, Object result) {
                dialogFragment.dismissAllowingStateLoss();
                if (!isAttached()) return;
                mView.get().openCoachHandBook();
            }
        });
        dialog.setDialogDismissListener(new DialogDismissListener() {
            @Override
            public void dismiss(DialogFragment dialog) {
                if (!isAttached()) return;
                mView.get().onDialogDismiss(dialog);
            }
        });
        dialog.show(fragmentManager, "NotificationDialog");
    }
}
